{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Fictional Army - Filtering and Sorting"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Introduction:\n",
    "\n",
    "This exercise was inspired by this [page](http://chrisalbon.com/python/)\n",
    "\n",
    "Special thanks to: https://github.com/chrisalbon for sharing the dataset and materials.\n",
    "\n",
    "### Step 1. Import the necessary libraries"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 2. This is the data given as a dictionary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create an example dataframe about a fictional army\n",
    "raw_data = {'regiment': ['Nighthawks', 'Nighthawks', 'Nighthawks', 'Nighthawks', 'Dragoons', 'Dragoons', 'Dragoons', 'Dragoons', 'Scouts', 'Scouts', 'Scouts', 'Scouts'],\n",
    "            'company': ['1st', '1st', '2nd', '2nd', '1st', '1st', '2nd', '2nd','1st', '1st', '2nd', '2nd'],\n",
    "            'deaths': [523, 52, 25, 616, 43, 234, 523, 62, 62, 73, 37, 35],\n",
    "            'battles': [5, 42, 2, 2, 4, 7, 8, 3, 4, 7, 8, 9],\n",
    "            'size': [1045, 957, 1099, 1400, 1592, 1006, 987, 849, 973, 1005, 1099, 1523],\n",
    "            'veterans': [1, 5, 62, 26, 73, 37, 949, 48, 48, 435, 63, 345],\n",
    "            'readiness': [1, 2, 3, 3, 2, 1, 2, 3, 2, 1, 2, 3],\n",
    "            'armored': [1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1],\n",
    "            'deserters': [4, 24, 31, 2, 3, 4, 24, 31, 2, 3, 2, 3],\n",
    "            'origin': ['Arizona', 'California', 'Texas', 'Florida', 'Maine', 'Iowa', 'Alaska', 'Washington', 'Oregon', 'Wyoming', 'Louisana', 'Georgia']}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 3. Create a dataframe and assign it to a variable called army. \n",
    "\n",
    "#### Don't forget to include the columns names in the order presented in the dictionary ('regiment', 'company', 'deaths'...) so that the column index order is consistent with the solutions. If omitted, pandas will order the columns alphabetically."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>regiment</th>\n",
       "      <th>company</th>\n",
       "      <th>deaths</th>\n",
       "      <th>battles</th>\n",
       "      <th>size</th>\n",
       "      <th>veterans</th>\n",
       "      <th>readiness</th>\n",
       "      <th>armored</th>\n",
       "      <th>deserters</th>\n",
       "      <th>origin</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Nighthawks</td>\n",
       "      <td>1st</td>\n",
       "      <td>523</td>\n",
       "      <td>5</td>\n",
       "      <td>1045</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>Arizona</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Nighthawks</td>\n",
       "      <td>1st</td>\n",
       "      <td>52</td>\n",
       "      <td>42</td>\n",
       "      <td>957</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>24</td>\n",
       "      <td>California</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Nighthawks</td>\n",
       "      <td>2nd</td>\n",
       "      <td>25</td>\n",
       "      <td>2</td>\n",
       "      <td>1099</td>\n",
       "      <td>62</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>31</td>\n",
       "      <td>Texas</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Nighthawks</td>\n",
       "      <td>2nd</td>\n",
       "      <td>616</td>\n",
       "      <td>2</td>\n",
       "      <td>1400</td>\n",
       "      <td>26</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>Florida</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Dragoons</td>\n",
       "      <td>1st</td>\n",
       "      <td>43</td>\n",
       "      <td>4</td>\n",
       "      <td>1592</td>\n",
       "      <td>73</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>Maine</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Dragoons</td>\n",
       "      <td>1st</td>\n",
       "      <td>234</td>\n",
       "      <td>7</td>\n",
       "      <td>1006</td>\n",
       "      <td>37</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>Iowa</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Dragoons</td>\n",
       "      <td>2nd</td>\n",
       "      <td>523</td>\n",
       "      <td>8</td>\n",
       "      <td>987</td>\n",
       "      <td>949</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>24</td>\n",
       "      <td>Alaska</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Dragoons</td>\n",
       "      <td>2nd</td>\n",
       "      <td>62</td>\n",
       "      <td>3</td>\n",
       "      <td>849</td>\n",
       "      <td>48</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>31</td>\n",
       "      <td>Washington</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>Scouts</td>\n",
       "      <td>1st</td>\n",
       "      <td>62</td>\n",
       "      <td>4</td>\n",
       "      <td>973</td>\n",
       "      <td>48</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>Oregon</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>Scouts</td>\n",
       "      <td>1st</td>\n",
       "      <td>73</td>\n",
       "      <td>7</td>\n",
       "      <td>1005</td>\n",
       "      <td>435</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>Wyoming</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>Scouts</td>\n",
       "      <td>2nd</td>\n",
       "      <td>37</td>\n",
       "      <td>8</td>\n",
       "      <td>1099</td>\n",
       "      <td>63</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>Louisana</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>Scouts</td>\n",
       "      <td>2nd</td>\n",
       "      <td>35</td>\n",
       "      <td>9</td>\n",
       "      <td>1523</td>\n",
       "      <td>345</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>Georgia</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      regiment company  deaths  battles  size  veterans  readiness  armored  \\\n",
       "0   Nighthawks     1st     523        5  1045         1          1        1   \n",
       "1   Nighthawks     1st      52       42   957         5          2        0   \n",
       "2   Nighthawks     2nd      25        2  1099        62          3        1   \n",
       "3   Nighthawks     2nd     616        2  1400        26          3        1   \n",
       "4     Dragoons     1st      43        4  1592        73          2        0   \n",
       "5     Dragoons     1st     234        7  1006        37          1        1   \n",
       "6     Dragoons     2nd     523        8   987       949          2        0   \n",
       "7     Dragoons     2nd      62        3   849        48          3        1   \n",
       "8       Scouts     1st      62        4   973        48          2        0   \n",
       "9       Scouts     1st      73        7  1005       435          1        0   \n",
       "10      Scouts     2nd      37        8  1099        63          2        1   \n",
       "11      Scouts     2nd      35        9  1523       345          3        1   \n",
       "\n",
       "    deserters      origin  \n",
       "0           4     Arizona  \n",
       "1          24  California  \n",
       "2          31       Texas  \n",
       "3           2     Florida  \n",
       "4           3       Maine  \n",
       "5           4        Iowa  \n",
       "6          24      Alaska  \n",
       "7          31  Washington  \n",
       "8           2      Oregon  \n",
       "9           3     Wyoming  \n",
       "10          2    Louisana  \n",
       "11          3     Georgia  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "army = pd.DataFrame(data=raw_data)\n",
    "army"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 4. Set the 'origin' colum as the index of the dataframe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "army.set_index('origin', inplace=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 5. Print only the column veterans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "origin\n",
       "Arizona         1\n",
       "California      5\n",
       "Texas          62\n",
       "Florida        26\n",
       "Maine          73\n",
       "Iowa           37\n",
       "Alaska        949\n",
       "Washington     48\n",
       "Oregon         48\n",
       "Wyoming       435\n",
       "Louisana       63\n",
       "Georgia       345\n",
       "Name: veterans, dtype: int64"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "army.veterans"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 6. Print the columns 'veterans' and 'deaths'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>veterans</th>\n",
       "      <th>deaths</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>origin</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Arizona</th>\n",
       "      <td>1</td>\n",
       "      <td>523</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>California</th>\n",
       "      <td>5</td>\n",
       "      <td>52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Texas</th>\n",
       "      <td>62</td>\n",
       "      <td>25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Florida</th>\n",
       "      <td>26</td>\n",
       "      <td>616</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Maine</th>\n",
       "      <td>73</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Iowa</th>\n",
       "      <td>37</td>\n",
       "      <td>234</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alaska</th>\n",
       "      <td>949</td>\n",
       "      <td>523</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Washington</th>\n",
       "      <td>48</td>\n",
       "      <td>62</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Oregon</th>\n",
       "      <td>48</td>\n",
       "      <td>62</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Wyoming</th>\n",
       "      <td>435</td>\n",
       "      <td>73</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Louisana</th>\n",
       "      <td>63</td>\n",
       "      <td>37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Georgia</th>\n",
       "      <td>345</td>\n",
       "      <td>35</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            veterans  deaths\n",
       "origin                      \n",
       "Arizona            1     523\n",
       "California         5      52\n",
       "Texas             62      25\n",
       "Florida           26     616\n",
       "Maine             73      43\n",
       "Iowa              37     234\n",
       "Alaska           949     523\n",
       "Washington        48      62\n",
       "Oregon            48      62\n",
       "Wyoming          435      73\n",
       "Louisana          63      37\n",
       "Georgia          345      35"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "army[[\"veterans\", \"deaths\"]]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 7. Print the name of all the columns."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['regiment', 'company', 'deaths', 'battles', 'size', 'veterans',\n",
       "       'readiness', 'armored', 'deserters'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "army.columns"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 8. Select the 'deaths', 'size' and 'deserters' columns from Maine and Alaska"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>deaths</th>\n",
       "      <th>size</th>\n",
       "      <th>deserters</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>origin</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Maine</th>\n",
       "      <td>43</td>\n",
       "      <td>1592</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alaska</th>\n",
       "      <td>523</td>\n",
       "      <td>987</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        deaths  size  deserters\n",
       "origin                         \n",
       "Maine       43  1592          3\n",
       "Alaska     523   987         24"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "army.loc[[\"Maine\", \"Alaska\"], [\"deaths\", \"size\", \"deserters\"]]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 9. Select the rows 3 to 7 and the columns 3 to 6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>deaths</th>\n",
       "      <th>battles</th>\n",
       "      <th>size</th>\n",
       "      <th>veterans</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>origin</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Texas</th>\n",
       "      <td>25</td>\n",
       "      <td>2</td>\n",
       "      <td>1099</td>\n",
       "      <td>62</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Florida</th>\n",
       "      <td>616</td>\n",
       "      <td>2</td>\n",
       "      <td>1400</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Maine</th>\n",
       "      <td>43</td>\n",
       "      <td>4</td>\n",
       "      <td>1592</td>\n",
       "      <td>73</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Iowa</th>\n",
       "      <td>234</td>\n",
       "      <td>7</td>\n",
       "      <td>1006</td>\n",
       "      <td>37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alaska</th>\n",
       "      <td>523</td>\n",
       "      <td>8</td>\n",
       "      <td>987</td>\n",
       "      <td>949</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         deaths  battles  size  veterans\n",
       "origin                                  \n",
       "Texas        25        2  1099        62\n",
       "Florida     616        2  1400        26\n",
       "Maine        43        4  1592        73\n",
       "Iowa        234        7  1006        37\n",
       "Alaska      523        8   987       949"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "army.iloc[2:7, 2:6]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 10. Select every row after the fourth row and all columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>regiment</th>\n",
       "      <th>company</th>\n",
       "      <th>deaths</th>\n",
       "      <th>battles</th>\n",
       "      <th>size</th>\n",
       "      <th>veterans</th>\n",
       "      <th>readiness</th>\n",
       "      <th>armored</th>\n",
       "      <th>deserters</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>origin</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Maine</th>\n",
       "      <td>Dragoons</td>\n",
       "      <td>1st</td>\n",
       "      <td>43</td>\n",
       "      <td>4</td>\n",
       "      <td>1592</td>\n",
       "      <td>73</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Iowa</th>\n",
       "      <td>Dragoons</td>\n",
       "      <td>1st</td>\n",
       "      <td>234</td>\n",
       "      <td>7</td>\n",
       "      <td>1006</td>\n",
       "      <td>37</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alaska</th>\n",
       "      <td>Dragoons</td>\n",
       "      <td>2nd</td>\n",
       "      <td>523</td>\n",
       "      <td>8</td>\n",
       "      <td>987</td>\n",
       "      <td>949</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Washington</th>\n",
       "      <td>Dragoons</td>\n",
       "      <td>2nd</td>\n",
       "      <td>62</td>\n",
       "      <td>3</td>\n",
       "      <td>849</td>\n",
       "      <td>48</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Oregon</th>\n",
       "      <td>Scouts</td>\n",
       "      <td>1st</td>\n",
       "      <td>62</td>\n",
       "      <td>4</td>\n",
       "      <td>973</td>\n",
       "      <td>48</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Wyoming</th>\n",
       "      <td>Scouts</td>\n",
       "      <td>1st</td>\n",
       "      <td>73</td>\n",
       "      <td>7</td>\n",
       "      <td>1005</td>\n",
       "      <td>435</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Louisana</th>\n",
       "      <td>Scouts</td>\n",
       "      <td>2nd</td>\n",
       "      <td>37</td>\n",
       "      <td>8</td>\n",
       "      <td>1099</td>\n",
       "      <td>63</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Georgia</th>\n",
       "      <td>Scouts</td>\n",
       "      <td>2nd</td>\n",
       "      <td>35</td>\n",
       "      <td>9</td>\n",
       "      <td>1523</td>\n",
       "      <td>345</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            regiment company  deaths  battles  size  veterans  readiness  \\\n",
       "origin                                                                     \n",
       "Maine       Dragoons     1st      43        4  1592        73          2   \n",
       "Iowa        Dragoons     1st     234        7  1006        37          1   \n",
       "Alaska      Dragoons     2nd     523        8   987       949          2   \n",
       "Washington  Dragoons     2nd      62        3   849        48          3   \n",
       "Oregon        Scouts     1st      62        4   973        48          2   \n",
       "Wyoming       Scouts     1st      73        7  1005       435          1   \n",
       "Louisana      Scouts     2nd      37        8  1099        63          2   \n",
       "Georgia       Scouts     2nd      35        9  1523       345          3   \n",
       "\n",
       "            armored  deserters  \n",
       "origin                          \n",
       "Maine             0          3  \n",
       "Iowa              1          4  \n",
       "Alaska            0         24  \n",
       "Washington        1         31  \n",
       "Oregon            0          2  \n",
       "Wyoming           0          3  \n",
       "Louisana          1          2  \n",
       "Georgia           1          3  "
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "army.iloc[4:, :]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 11. Select every row up to the 4th row and all columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>regiment</th>\n",
       "      <th>company</th>\n",
       "      <th>deaths</th>\n",
       "      <th>battles</th>\n",
       "      <th>size</th>\n",
       "      <th>veterans</th>\n",
       "      <th>readiness</th>\n",
       "      <th>armored</th>\n",
       "      <th>deserters</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>origin</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Arizona</th>\n",
       "      <td>Nighthawks</td>\n",
       "      <td>1st</td>\n",
       "      <td>523</td>\n",
       "      <td>5</td>\n",
       "      <td>1045</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>California</th>\n",
       "      <td>Nighthawks</td>\n",
       "      <td>1st</td>\n",
       "      <td>52</td>\n",
       "      <td>42</td>\n",
       "      <td>957</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Texas</th>\n",
       "      <td>Nighthawks</td>\n",
       "      <td>2nd</td>\n",
       "      <td>25</td>\n",
       "      <td>2</td>\n",
       "      <td>1099</td>\n",
       "      <td>62</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Florida</th>\n",
       "      <td>Nighthawks</td>\n",
       "      <td>2nd</td>\n",
       "      <td>616</td>\n",
       "      <td>2</td>\n",
       "      <td>1400</td>\n",
       "      <td>26</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              regiment company  deaths  battles  size  veterans  readiness  \\\n",
       "origin                                                                       \n",
       "Arizona     Nighthawks     1st     523        5  1045         1          1   \n",
       "California  Nighthawks     1st      52       42   957         5          2   \n",
       "Texas       Nighthawks     2nd      25        2  1099        62          3   \n",
       "Florida     Nighthawks     2nd     616        2  1400        26          3   \n",
       "\n",
       "            armored  deserters  \n",
       "origin                          \n",
       "Arizona           1          4  \n",
       "California        0         24  \n",
       "Texas             1         31  \n",
       "Florida           1          2  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "army.iloc[:4, :]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 12. Select the 3rd column up to the 7th column"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>deaths</th>\n",
       "      <th>battles</th>\n",
       "      <th>size</th>\n",
       "      <th>veterans</th>\n",
       "      <th>readiness</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>origin</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Arizona</th>\n",
       "      <td>523</td>\n",
       "      <td>5</td>\n",
       "      <td>1045</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>California</th>\n",
       "      <td>52</td>\n",
       "      <td>42</td>\n",
       "      <td>957</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Texas</th>\n",
       "      <td>25</td>\n",
       "      <td>2</td>\n",
       "      <td>1099</td>\n",
       "      <td>62</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Florida</th>\n",
       "      <td>616</td>\n",
       "      <td>2</td>\n",
       "      <td>1400</td>\n",
       "      <td>26</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Maine</th>\n",
       "      <td>43</td>\n",
       "      <td>4</td>\n",
       "      <td>1592</td>\n",
       "      <td>73</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Iowa</th>\n",
       "      <td>234</td>\n",
       "      <td>7</td>\n",
       "      <td>1006</td>\n",
       "      <td>37</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alaska</th>\n",
       "      <td>523</td>\n",
       "      <td>8</td>\n",
       "      <td>987</td>\n",
       "      <td>949</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Washington</th>\n",
       "      <td>62</td>\n",
       "      <td>3</td>\n",
       "      <td>849</td>\n",
       "      <td>48</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Oregon</th>\n",
       "      <td>62</td>\n",
       "      <td>4</td>\n",
       "      <td>973</td>\n",
       "      <td>48</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Wyoming</th>\n",
       "      <td>73</td>\n",
       "      <td>7</td>\n",
       "      <td>1005</td>\n",
       "      <td>435</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Louisana</th>\n",
       "      <td>37</td>\n",
       "      <td>8</td>\n",
       "      <td>1099</td>\n",
       "      <td>63</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Georgia</th>\n",
       "      <td>35</td>\n",
       "      <td>9</td>\n",
       "      <td>1523</td>\n",
       "      <td>345</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            deaths  battles  size  veterans  readiness\n",
       "origin                                                \n",
       "Arizona        523        5  1045         1          1\n",
       "California      52       42   957         5          2\n",
       "Texas           25        2  1099        62          3\n",
       "Florida        616        2  1400        26          3\n",
       "Maine           43        4  1592        73          2\n",
       "Iowa           234        7  1006        37          1\n",
       "Alaska         523        8   987       949          2\n",
       "Washington      62        3   849        48          3\n",
       "Oregon          62        4   973        48          2\n",
       "Wyoming         73        7  1005       435          1\n",
       "Louisana        37        8  1099        63          2\n",
       "Georgia         35        9  1523       345          3"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "army.iloc[:, 2:7]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 13. Select rows where df.deaths is greater than 50"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>regiment</th>\n",
       "      <th>company</th>\n",
       "      <th>deaths</th>\n",
       "      <th>battles</th>\n",
       "      <th>size</th>\n",
       "      <th>veterans</th>\n",
       "      <th>readiness</th>\n",
       "      <th>armored</th>\n",
       "      <th>deserters</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>origin</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Arizona</th>\n",
       "      <td>Nighthawks</td>\n",
       "      <td>1st</td>\n",
       "      <td>523</td>\n",
       "      <td>5</td>\n",
       "      <td>1045</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>California</th>\n",
       "      <td>Nighthawks</td>\n",
       "      <td>1st</td>\n",
       "      <td>52</td>\n",
       "      <td>42</td>\n",
       "      <td>957</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Florida</th>\n",
       "      <td>Nighthawks</td>\n",
       "      <td>2nd</td>\n",
       "      <td>616</td>\n",
       "      <td>2</td>\n",
       "      <td>1400</td>\n",
       "      <td>26</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Iowa</th>\n",
       "      <td>Dragoons</td>\n",
       "      <td>1st</td>\n",
       "      <td>234</td>\n",
       "      <td>7</td>\n",
       "      <td>1006</td>\n",
       "      <td>37</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alaska</th>\n",
       "      <td>Dragoons</td>\n",
       "      <td>2nd</td>\n",
       "      <td>523</td>\n",
       "      <td>8</td>\n",
       "      <td>987</td>\n",
       "      <td>949</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Washington</th>\n",
       "      <td>Dragoons</td>\n",
       "      <td>2nd</td>\n",
       "      <td>62</td>\n",
       "      <td>3</td>\n",
       "      <td>849</td>\n",
       "      <td>48</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Oregon</th>\n",
       "      <td>Scouts</td>\n",
       "      <td>1st</td>\n",
       "      <td>62</td>\n",
       "      <td>4</td>\n",
       "      <td>973</td>\n",
       "      <td>48</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Wyoming</th>\n",
       "      <td>Scouts</td>\n",
       "      <td>1st</td>\n",
       "      <td>73</td>\n",
       "      <td>7</td>\n",
       "      <td>1005</td>\n",
       "      <td>435</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              regiment company  deaths  battles  size  veterans  readiness  \\\n",
       "origin                                                                       \n",
       "Arizona     Nighthawks     1st     523        5  1045         1          1   \n",
       "California  Nighthawks     1st      52       42   957         5          2   \n",
       "Florida     Nighthawks     2nd     616        2  1400        26          3   \n",
       "Iowa          Dragoons     1st     234        7  1006        37          1   \n",
       "Alaska        Dragoons     2nd     523        8   987       949          2   \n",
       "Washington    Dragoons     2nd      62        3   849        48          3   \n",
       "Oregon          Scouts     1st      62        4   973        48          2   \n",
       "Wyoming         Scouts     1st      73        7  1005       435          1   \n",
       "\n",
       "            armored  deserters  \n",
       "origin                          \n",
       "Arizona           1          4  \n",
       "California        0         24  \n",
       "Florida           1          2  \n",
       "Iowa              1          4  \n",
       "Alaska            0         24  \n",
       "Washington        1         31  \n",
       "Oregon            0          2  \n",
       "Wyoming           0          3  "
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "army[army[\"deaths\"] > 50]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 14. Select rows where df.deaths is greater than 500 or less than 50"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>regiment</th>\n",
       "      <th>company</th>\n",
       "      <th>deaths</th>\n",
       "      <th>battles</th>\n",
       "      <th>size</th>\n",
       "      <th>veterans</th>\n",
       "      <th>readiness</th>\n",
       "      <th>armored</th>\n",
       "      <th>deserters</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>origin</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Arizona</th>\n",
       "      <td>Nighthawks</td>\n",
       "      <td>1st</td>\n",
       "      <td>523</td>\n",
       "      <td>5</td>\n",
       "      <td>1045</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Texas</th>\n",
       "      <td>Nighthawks</td>\n",
       "      <td>2nd</td>\n",
       "      <td>25</td>\n",
       "      <td>2</td>\n",
       "      <td>1099</td>\n",
       "      <td>62</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Florida</th>\n",
       "      <td>Nighthawks</td>\n",
       "      <td>2nd</td>\n",
       "      <td>616</td>\n",
       "      <td>2</td>\n",
       "      <td>1400</td>\n",
       "      <td>26</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Maine</th>\n",
       "      <td>Dragoons</td>\n",
       "      <td>1st</td>\n",
       "      <td>43</td>\n",
       "      <td>4</td>\n",
       "      <td>1592</td>\n",
       "      <td>73</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alaska</th>\n",
       "      <td>Dragoons</td>\n",
       "      <td>2nd</td>\n",
       "      <td>523</td>\n",
       "      <td>8</td>\n",
       "      <td>987</td>\n",
       "      <td>949</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Louisana</th>\n",
       "      <td>Scouts</td>\n",
       "      <td>2nd</td>\n",
       "      <td>37</td>\n",
       "      <td>8</td>\n",
       "      <td>1099</td>\n",
       "      <td>63</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Georgia</th>\n",
       "      <td>Scouts</td>\n",
       "      <td>2nd</td>\n",
       "      <td>35</td>\n",
       "      <td>9</td>\n",
       "      <td>1523</td>\n",
       "      <td>345</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            regiment company  deaths  battles  size  veterans  readiness  \\\n",
       "origin                                                                     \n",
       "Arizona   Nighthawks     1st     523        5  1045         1          1   \n",
       "Texas     Nighthawks     2nd      25        2  1099        62          3   \n",
       "Florida   Nighthawks     2nd     616        2  1400        26          3   \n",
       "Maine       Dragoons     1st      43        4  1592        73          2   \n",
       "Alaska      Dragoons     2nd     523        8   987       949          2   \n",
       "Louisana      Scouts     2nd      37        8  1099        63          2   \n",
       "Georgia       Scouts     2nd      35        9  1523       345          3   \n",
       "\n",
       "          armored  deserters  \n",
       "origin                        \n",
       "Arizona         1          4  \n",
       "Texas           1         31  \n",
       "Florida         1          2  \n",
       "Maine           0          3  \n",
       "Alaska          0         24  \n",
       "Louisana        1          2  \n",
       "Georgia         1          3  "
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "army[(army[\"deaths\"] > 500) | (army[\"deaths\"] < 50)]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 15. Select all the regiments not named \"Dragoons\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>regiment</th>\n",
       "      <th>company</th>\n",
       "      <th>deaths</th>\n",
       "      <th>battles</th>\n",
       "      <th>size</th>\n",
       "      <th>veterans</th>\n",
       "      <th>readiness</th>\n",
       "      <th>armored</th>\n",
       "      <th>deserters</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>origin</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Arizona</th>\n",
       "      <td>Nighthawks</td>\n",
       "      <td>1st</td>\n",
       "      <td>523</td>\n",
       "      <td>5</td>\n",
       "      <td>1045</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>California</th>\n",
       "      <td>Nighthawks</td>\n",
       "      <td>1st</td>\n",
       "      <td>52</td>\n",
       "      <td>42</td>\n",
       "      <td>957</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Texas</th>\n",
       "      <td>Nighthawks</td>\n",
       "      <td>2nd</td>\n",
       "      <td>25</td>\n",
       "      <td>2</td>\n",
       "      <td>1099</td>\n",
       "      <td>62</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Florida</th>\n",
       "      <td>Nighthawks</td>\n",
       "      <td>2nd</td>\n",
       "      <td>616</td>\n",
       "      <td>2</td>\n",
       "      <td>1400</td>\n",
       "      <td>26</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Oregon</th>\n",
       "      <td>Scouts</td>\n",
       "      <td>1st</td>\n",
       "      <td>62</td>\n",
       "      <td>4</td>\n",
       "      <td>973</td>\n",
       "      <td>48</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Wyoming</th>\n",
       "      <td>Scouts</td>\n",
       "      <td>1st</td>\n",
       "      <td>73</td>\n",
       "      <td>7</td>\n",
       "      <td>1005</td>\n",
       "      <td>435</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Louisana</th>\n",
       "      <td>Scouts</td>\n",
       "      <td>2nd</td>\n",
       "      <td>37</td>\n",
       "      <td>8</td>\n",
       "      <td>1099</td>\n",
       "      <td>63</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Georgia</th>\n",
       "      <td>Scouts</td>\n",
       "      <td>2nd</td>\n",
       "      <td>35</td>\n",
       "      <td>9</td>\n",
       "      <td>1523</td>\n",
       "      <td>345</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              regiment company  deaths  battles  size  veterans  readiness  \\\n",
       "origin                                                                       \n",
       "Arizona     Nighthawks     1st     523        5  1045         1          1   \n",
       "California  Nighthawks     1st      52       42   957         5          2   \n",
       "Texas       Nighthawks     2nd      25        2  1099        62          3   \n",
       "Florida     Nighthawks     2nd     616        2  1400        26          3   \n",
       "Oregon          Scouts     1st      62        4   973        48          2   \n",
       "Wyoming         Scouts     1st      73        7  1005       435          1   \n",
       "Louisana        Scouts     2nd      37        8  1099        63          2   \n",
       "Georgia         Scouts     2nd      35        9  1523       345          3   \n",
       "\n",
       "            armored  deserters  \n",
       "origin                          \n",
       "Arizona           1          4  \n",
       "California        0         24  \n",
       "Texas             1         31  \n",
       "Florida           1          2  \n",
       "Oregon            0          2  \n",
       "Wyoming           0          3  \n",
       "Louisana          1          2  \n",
       "Georgia           1          3  "
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "army[army[\"regiment\"] != \"Dragoons\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 16. Select the rows called Texas and Arizona"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>regiment</th>\n",
       "      <th>company</th>\n",
       "      <th>deaths</th>\n",
       "      <th>battles</th>\n",
       "      <th>size</th>\n",
       "      <th>veterans</th>\n",
       "      <th>readiness</th>\n",
       "      <th>armored</th>\n",
       "      <th>deserters</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>origin</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Texas</th>\n",
       "      <td>Nighthawks</td>\n",
       "      <td>2nd</td>\n",
       "      <td>25</td>\n",
       "      <td>2</td>\n",
       "      <td>1099</td>\n",
       "      <td>62</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Arizona</th>\n",
       "      <td>Nighthawks</td>\n",
       "      <td>1st</td>\n",
       "      <td>523</td>\n",
       "      <td>5</td>\n",
       "      <td>1045</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           regiment company  deaths  battles  size  veterans  readiness  \\\n",
       "origin                                                                    \n",
       "Texas    Nighthawks     2nd      25        2  1099        62          3   \n",
       "Arizona  Nighthawks     1st     523        5  1045         1          1   \n",
       "\n",
       "         armored  deserters  \n",
       "origin                       \n",
       "Texas          1         31  \n",
       "Arizona        1          4  "
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "army.loc[[\"Texas\", \"Arizona\"], :]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 17. Select the third cell in the row named Arizona"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "origin\n",
       "Arizona    523\n",
       "Name: deaths, dtype: int64"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "army.loc[[\"Arizona\"]].iloc[:, 2]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 18. Select the third cell down in the column named deaths"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "deaths    25\n",
       "Name: Texas, dtype: int64"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "army.loc[:, [\"deaths\"]].iloc[2]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
